<?php
namespace app\admin\controller;
use think\facade\Db;


class Home extends Admin
{
	
	//头部消息通知
	function getNotice(){
		$data = [
			[
				'num'=>5,
				'title'=>'条评论待回复',
				'url'=>(string)url('admin/Member/index'),
			],
			[
				'num'=>12,
				'title'=>'条订单待处理',
				'url'=>(string)url('admin/Map/index'),
			],
			[
				'num'=>50,
				'title'=>'条私信待处理',
				'url'=>(string)url('admin/Member/index'),
			],
		];
		
		return json(['status'=>200,'data'=>$data]);
	}
	
	//仪表盘数据
	function index(){
		$show_home_chats = !is_null(config('my.show_home_chats')) ? config('my.show_home_chats') : true;	//是否显示首页图表
		
		//折线图数据
		$echat_data['day_count'] = [
			'title'=>'当月业绩折线图',
			'day'=>[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],	//每月天数
			'data'=>[0,0,0,0,0,126,246,452,45,36,479,588,434,9,18,27,18,88,45,0,0,0,0,0,0,0,0,0,0,0]	//每天数据
		];
		
		//圆形图数据
		$echat_data['cycle_data'] = [
			'title'=>'网站访问类别',
			'catagory'=>["超级管理员", "管理员", "作者", "普通用户", "普通用户","访客"],
			'data'=> [
				['value'=>rand(0,1000) , 'name'=> "超级管理员" ],
				['value'=>rand(0,1000) , 'name'=> "管理员" ],
				['value'=>rand(0,1000) , 'name'=> "作者" ],
				['value'=>rand(0,1000) , 'name'=> "普通用户" ],
				['value'=>rand(0,1000) , 'name'=> "访客" ],
			]
		];
		
		
		if($show_home_chats){
			$data['echat_data'] = $echat_data;
		}
		$data['card_data'] = $this->getCardData();
		$data['menus'] = $this->getMenuLink();
		$data['status'] = 200;
		
		return json($data);
		
	}
	
	
	//首页统计数据
	private function getCardData(){
		$card_data = [	//头部统计数据
			[
			  'card_title_icon'=>"el-icon-user",
			  'card_title'=> "访问",
			  'card_cycle'=> "年",
			  'card_cycle_back_color'=> "#409EFF",
			  'bottom_title'=> "访问总量",
			  'vist_num'=> rand(0,100000),
			  'vist_all_num'=> rand(0,100000),
			  'vist_all_icon'=> "el-icon-trophy",
			],
			[
			  'card_title_icon'=> "el-icon-download",
			  'card_title'=> "下载",
			  'card_cycle'=> "月",
			  'card_cycle_back_color'=> "#67C23A",
			  'bottom_title'=> "下载总量",
			  'vist_num'=> rand(0,100000),
			  'vist_all_num'=> rand(0,100000),
			  'vist_all_icon'=> "el-icon-download",
			],
			[
			  'card_title_icon'=> "el-icon-wallet",
			  'card_title'=> "收入",
			  'card_cycle'=> "日",
			  'card_cycle_back_color'=> "#F56C6C",
			  'bottom_title'=> "总收入",
			  'vist_num'=> rand(0,100000),
			  'vist_all_num'=> rand(0,100000),
			  'vist_all_icon'=> "el-icon-coin",
			],
			[
			  'card_title_icon'=> "el-icon-coordinate",
			  'card_title'=> "用户",
			  'card_cycle'=> "月",
			  'card_cycle_back_color'=> "#E6A23C",
			  'bottom_title'=> "总用户",
			  'vist_num'=> rand(0,100000),
			  'vist_all_num'=> rand(0,100000),
			  'vist_all_icon'=> "el-icon-data-line",
			],
		];
		
		return $card_data;
	}
	
	
	//获取首页快捷导航
	private function getMenuLink(){
		$show_home_menu = !is_null(config('my.show_home_menu')) ? config('my.show_home_menu') : true;	//是否显示首页快捷导航
		if($show_home_menu){
			$data = Db::name('menu')->field('title,menu_pic,controller_name')->where('home_show',1)->limit(8)->select()->toArray();
			foreach($data as $k=>$v){
				$data[$k]['url'] = (string)url('admin/'.str_replace('/','.',$v['controller_name']).'/index');
			}
			return $data;
		}
	}
	
	
}
